EditItemWindow = function(){
	var this_window = this;
	
	
	this.setData = function(data){
		form.form.setValues(data);
	};
//	this.setItemId = function(val){
//		idText.setValue(val);
//	};
//	
//	var loadItem = function(){
//		this_window.el.mask("读取中 ...","x-mask-loading");
//		Ext.Ajax.request({
//			url : "item/findByIdForInput.action",
//			params : {"item.id": idText.getValue()},
//			success : function(resp){
//				this_window.el.unmask();
//				var obj = Ext.decode(resp.responseText);
//				form.form.setValues(object2Entity(obj,"item"));
//			}
//		});
//	};
	
	var update = function(){
		if(!form.form.isValid()){
			return false;
		}
		var params = form.form.getFieldValues();
		params["type"]= "sell";
		Ajax({
			url : "item/update.action",
			params : params,
			maskTarget : this_window,
			window : this_window,
			success : function(){
//				setDetailPanel.getTopToolbar().init();
			}
		});
	};
	
	var reloadComboBox = function(){
		hospitalCombo.store.reload();
		productCombo.store.reload();
		personCombo.store.reload();
		unitCombo.store.reload();
	};
	this.reloadComboBox = reloadComboBox;
	
	var hospitalCombo = new Combobox("item.hospital.id","医院名称","hospital");
	var productCombo = new Combobox("item.product.id","货品名称","product");
	var unitCombo = new Combobox("item.unit.id","货品单位","unit");
	var personCombo = new Combobox("item.person.id","相关人员","person");
	
	var idText = new Ext.form.Hidden({
		name : "item.id"
	});
	
//	var personCombo = new Ext.form.ComboBox({
//		fieldLabel : "相关人员",
//		name : "item.personId",
//		editable : false,
//		typeAhead: true,
//	    triggerAction: 'all',
//	    lazyRender:true,
//	    mode: 'local',
//	    forceSelection : true,
//	    store: new Ext.data.JsonStore({
//	    	url : "person/findAll.action",
//	        fields: ["id","name"]
//	    }),
//	    valueField: "id",
//	    displayField: "name"
//	});
	
	this.listeners = {
		hide : function(){
			form.form.reset();
		},
		show : function(){
//			loadItem();
//			reloadComboBox();
		}
	};
	
	var form = new Ext.form.FormPanel({
		frame : true,
		padding : 5,
		defaults : {
			labelAlign : "right",
			labelWidth : 60,
			defaults : {
				xtype : 'textfield',
				anchor : "95%",
				allowBlank : false
			}
		},
		items : [{
			xtype : "fieldset",
			title : "项目信息",
			items : [hospitalCombo,productCombo,personCombo,unitCombo]
		},{
			xtype : "fieldset",
			title : "销售信息",
			items : [idText,{
				fieldLabel : "发货日期",
				name : "item.sellDate",
				xtype : "datefield",
				format : "Y/m/d"
			},{
				fieldLabel : "发货数量",
				name : "item.count",
				xtype : "numberfield",
				allowNegative : false
				
			},{
				fieldLabel : "售价(元)",
				name : "item.sellPrice",
				xtype : "numberfield",
				allowNegative : false
			},{
				fieldLabel : "进价(元)",
				name : "item.buyPrice",
				xtype : "numberfield",
				allowNegative : false
			}]
		}]
	});
	EditItemWindow.superclass.constructor.call(this, {
		title : "修改销售信息",
		iconCls : "edit",
		width : 400,
		border : false,
		autoHeight : true,
		closeAction : "hide",
		modal : true,
		items : [form],
		buttons : [{
			text : "保存",
			handler : update
		},{
			text : "取消",
			handler : function(){
				this_window.hide();
			}
		}]
	});
};
Ext.extend(EditItemWindow, Ext.Window);
var editItemWindow = new EditItemWindow();